// 记分牌
class ScorePanel {
    // 表示当前分数
    score = 0;
    // 表示当前等级
    level = 1;
    scoreEle: HTMLElement;
    levelEle: HTMLElement;

    // 设置level最高值
    maxLevel: number;
    // 设置每多少分升一级
    upScore: number;
    constructor(maxLevel: number = 10, upScore: number = 20) {
        this.levelEle = document.getElementsByClassName('level')[0] as HTMLElement;
        this.scoreEle = document.getElementsByClassName('score')[0] as HTMLElement;
        this.maxLevel = maxLevel;
        this.upScore = upScore;
    }
    // 增加食物，以及根据分数增加等级
    addScore() {
        this.scoreEle.innerHTML = ++this.score + '';
        if (this.score % this.upScore === 0) {
            this.addLevel()
        }
    }

    addLevel() {
        if (this.level >= this.maxLevel) return;
        this.levelEle.innerHTML = ++this.level + '';
    }
}

// const panel = new ScorePanel(5, 4)
// for(let i = 0;i < 29; i++) {
//     panel.addScore()
// }

export default ScorePanel;